//对axios函数库进行二次封装
import axios from "axios";

import {message} from 'ant-design-vue';

const http = axios.create({
    baseURL: 'http://localhost:8088/', // 请求后端接口的baseurl
    timeout: 5000, // 设置请求的超时时间
    withCredentials: true, // 允许跨域请求时携带cookie
})

// 请求拦截器
http.interceptors.request.use(config => {
        // 例如
        // config.headers.Authorization = `Bearer ${引入token}`
        return config
    },
    err => {
        return Promise.reject(err)
    })


// 响应拦截器
http.interceptors.response.use(response => {
        //统一错误提示
        if (!response.data.flag) {
            message.error(response.data.message, 3).then(() =>{
                console.log(response)
            } )
        }
        return response
    },
    err => {
        return Promise.reject(err)
    })


export function get(url: string, params: any) {
    return http.get(url, {params})
}

export function post(url: string, data: any) {
    return http.post(url, {data})
}

export default http

